package com.erp.produce.controller;

import com.erp.common.ResponseMessage;
import com.erp.common.controller.BaseControllerPowerful;
import com.erp.common.service.BaseService;
import com.erp.produce.entity.ProductionTask;
import com.erp.produce.service.OrderService;
import com.erp.produce.service.ProductionTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Api("原生产任务信息接口")
@RestController
@RequestMapping("/prodtask")
public class ProductionTaskController extends BaseControllerPowerful<ProductionTask> {

    @Autowired
    ProductionTaskService service;

    @Autowired
    OrderService orderService;


    @Override
    protected BaseService getService() {
        return this.service;
    }


    @ApiOperation("新增生产任务（支持多选）")
    @PostMapping("/add/tasks")
    public ResponseMessage saveTasks(@RequestBody ProductionTask[] tasks){
//        for (int i = 0; i < tasks.length; i++) {
//            System.out.println(tasks[i]);
//        }
        if (service.saveTasks(Arrays.asList(tasks))){
            return ResponseMessage.ok();
        }
        return ResponseMessage.fail("分发原材料失败，请重试");
    }

    @GetMapping("/list")
    public ResponseMessage list(Long orderId){
        List<ProductionTask> list = service.list(orderId);
        if (list.size()>0) {
            return new ResponseMessage(list);
        }
        return ResponseMessage.fail("无数据");
    }

}
